/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__frct_del.c                                      */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/17 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frlog.h"
#include "frmem.h"
#include "frlist.h"
#include "frsutl.h"
#include "frhash2.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frct_mng.h"
#include "apmtest_cunit.h"
#include "frct_hash.h"

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}

void __frct_del(Frlist_node *p_st_node);
void __hash_node_free(Frlist_node *p_st_node);

extern Frhash_header *g_p_st_hash_ct;


static void __case1(void)
{
    Frlist_node *p_st_node = NULL;

    __frct_del(p_st_node);

    return;
}

static void __case2(void)
{
    Frlist_node *p_st_node = NULL;
    Conntrack *p_st_ct = NULL;
    char *p_key = NULL;
    int i_key_len = 15;
    unsigned int ui_table_size = 65535;

    g_p_st_hash_ct=NULL;
    frct_hash_init(ui_table_size);

    p_key = (char *)frmalloc(i_key_len);

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct,0x00,sizeof(Conntrack));
    p_st_ct->src_ip = iptools_parse_ipaddr("192.168.1.1");
    p_st_ct->src_port = 80;
    p_st_ct->dst_ip = iptools_parse_ipaddr("192.168.0.1");
    p_st_ct->dst_port = 22;
    p_st_ct->ip_proto = 6;

    i_key_len = frct_hash_key(p_st_ct->ip_proto, p_st_ct->src_ip, p_st_ct->src_port
                            , p_st_ct->dst_ip, p_st_ct->dst_port, p_key, i_key_len);

    p_st_node = frct_hash_add(p_st_ct, p_key, i_key_len);

    __frct_del(p_st_node);

    p_st_node = frct_hash_get(p_st_ct->ip_proto, p_st_ct->src_ip, p_st_ct->src_port, p_st_ct->dst_ip, p_st_ct->dst_port);

    CU_ASSERT_PTR_NULL(p_st_node);

    frfree(p_st_ct);
    frfree(p_key);
    frhash2_free2(g_p_st_hash_ct,__hash_node_free);

    return;
}


int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t__frct_del 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);

 //  	CU_add_test(pSuite, "case3", case3);

 //  	CU_add_test(pSuite, "case4", case4);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();

    return 0;
}